/*
 * Copyright 2010 Kevin L'Huillier <klhuillier@gmail.com>
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package org.lhuillier.pwsafe.model;


import static org.lhuillier.pwsafe.model.PrefStorageType.*;


public enum IntegerPrefType {
    /**
     * Width of the first column.
     */
    COLUMN_1_WIDTH(-1, APPLICATION, 0, Integer.MAX_VALUE),
    /**
     * Width of the second column.
     */
    COLUMN_2_WIDTH(-1, APPLICATION, 0, Integer.MAX_VALUE),
    /**
     * Width of the third column.
     */
    COLUMN_3_WIDTH(-1, APPLICATION, 0, Integer.MAX_VALUE),
    /**
     * Width of the fourth column.
     */
    COLUMN_4_WIDTH(-1, APPLICATION, 0, Integer.MAX_VALUE),
    /**
     * The column that the list is sorted by. Sorting direction is determined
     * by {@link BooleanPrefType#SORT_ASCENDING}
     */
    SORTED_COLUMN(0, APPLICATION, 0, 15),
    /**
     * Length of passwords which are generated.
     */
    PW_DEFAULT_LENGTH(8, DATABASE, 4, 1024),
    /**
     * The most items to list in the Most-Recently Used menu of recent
     * databases.
     */
    MAX_MRU_ITEMS(4, APPLICATION, 0, 20),
    /**
     * The number of minutes after there is no activity to automatically lock
     * the password database.
     */
    IDLE_TIMEOUT(5, DATABASE, 1, 120),
    /**
     * What to do when the user double-clicks on an entry in the list.
     */
    DOUBLE_CLICK_ACTION(DoubleClickAction.COPY_PASSWORD.ordinal(), APPLICATION,
            0, DoubleClickAction.values().length - 1),
    /**
     * Value is the keycode. &lt;=0 is disabled.
     */
    HOT_KEY(0, APPLICATION, -1, -1),
    /**
     * Maximum recent entry items.
     */
    MAX_RE_ITEMS(25, APPLICATION, 0, 25),
    /**
     * The default way to display the Tree View when opening a database.
     */
    TREE_DISPLAY_STATUS_AT_OPEN(TreeDisplayType.ALL_COLLAPSED.ordinal(),
            DATABASE, 0, TreeDisplayType.values().length - 1),
    /**
     * The number of previous passwords to keep in the password history field
     * for an entry. This can be overridden for individual records.
     */
    NUM_PW_HISTORY_DEFAULT(3, DATABASE, 0, 255),
    /**
     * What to optionally attach to backup filenames to distinguish them.
     */
    BACKUP_SUFFIX(BackupMask.NONE.ordinal(), APPLICATION, 0,
            BackupMask.values().length - 1),
    /**
     * The most backup files to keep around. If no backup suffix is used, there
     * will only ever be one backup file.
     */
    BACKUP_MAX_INCREMENTED(1, APPLICATION, 1, 999),
    /**
     * The number of days to warn the user of an expiring password. This only
     * takes effect if {@link BooleanPrefType#PRE_EXPIRY_WARN} is true.
     */
    PRE_EXPIRY_WARN_DAYS(1, APPLICATION, 1, 30),
    CLOSED_TRAY_ICON_COLOR(TrayIconColor.BLACK.ordinal(), APPLICATION, 0,
            TrayIconColor.values().length - 1),
    /**
     * The minimum number of digits 0-9 to use when generating a password.
     */
    PW_DIGIT_MIN_LENGTH(0, DATABASE, 0, 1024),
    /**
     * The minimum number of lowercase letters to use when generating a
     * password.
     */
    PW_LOWERCASE_MIN_LENGTH(0, DATABASE, 0, 1024),
    /**
     * The minimum number of symbols to use when generating a password.
     */
    PW_SYMBOL_MIN_LENGTH(0, DATABASE, 0, 1024),
    /**
     * The minimum number of uppercase letters to use when generating a
     * password.
     */
    PW_UPPERCASE_MIN_LENGTH(0, DATABASE, 0, 1024),
    OPT_SHORTCUT_COLUMN_WIDTH(92, APPLICATION, 10, 512);

    private final int defaultValue;
    private final PrefStorageType storageType;
    private final int minValue;
    private final int maxValue;

    IntegerPrefType(int defaultValue, PrefStorageType storageType,
            int minValue, int maxValue) {
        this.defaultValue = defaultValue;
        this.storageType = storageType;
        this.minValue = minValue;
        this.maxValue = maxValue;
    }

    public int getDefaultValue() {
        return defaultValue;
    }

    public PrefStorageType getStorageType() {
        return storageType;
    }

    public int getMinValue() {
        return minValue;
    }

    public int getMaxValue() {
        return maxValue;
    }

    public static IntegerPrefType forId(int id) {
        IntegerPrefType[] values = values();
        if (id < 0 || id >= values.length) {
            return null;
        }
        return values[id];
    }
}
